<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.8.11"/>
<title>ESP8266 ILI9341 display support code with printf sources, wire-frame viewer and custom fonts: xpt2046/xpt2046.c Source File</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/searchdata.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<script type="text/javascript">
  $(document).ready(function() { init_search(); });
</script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  <td id="projectalign" style="padding-left: 0.5em;">
   <div id="projectname">ESP8266 ILI9341 display support code with printf sources, wire-frame viewer and custom fonts
   &#160;<span id="projectnumber">1.0</span>
   </div>
   <div id="projectbrief">ESP8266ILI9341DisplayProject</div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.11 -->
<script type="text/javascript">
var searchBox = new SearchBox("searchBox", "search",false,'Search');
</script>
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>Main&#160;Page</span></a></li>
      <li><a href="pages.html"><span>Related&#160;Pages</span></a></li>
      <li><a href="annotated.html"><span>Data&#160;Structures</span></a></li>
      <li class="current"><a href="files.html"><span>Files</span></a></li>
      <li>
        <div id="MSearchBox" class="MSearchBoxInactive">
        <span class="left">
          <img id="MSearchSelect" src="search/mag_sel.png"
               onmouseover="return searchBox.OnSearchSelectShow()"
               onmouseout="return searchBox.OnSearchSelectHide()"
               alt=""/>
          <input type="text" id="MSearchField" value="Search" accesskey="S"
               onfocus="searchBox.OnSearchFieldFocus(true)" 
               onblur="searchBox.OnSearchFieldFocus(false)" 
               onkeyup="searchBox.OnSearchFieldChange(event)"/>
          </span><span class="right">
            <a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.png" alt=""/></a>
          </span>
        </div>
      </li>
    </ul>
  </div>
  <div id="navrow2" class="tabs2">
    <ul class="tablist">
      <li><a href="files.html"><span>File&#160;List</span></a></li>
      <li><a href="globals.html"><span>Globals</span></a></li>
    </ul>
  </div>
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>

<div id="nav-path" class="navpath">
  <ul>
<li class="navelem"><a class="el" href="dir_0e80fb08802ded836bfad3909581be7f.html">xpt2046</a></li>  </ul>
</div>
</div><!-- top -->
<div class="header">
  <div class="headertitle">
<div class="title">xpt2046.c</div>  </div>
</div><!--header-->
<div class="contents">
<a href="xpt2046_8c.html">Go to the documentation of this file.</a><div class="fragment"><div class="line"><a name="l00001"></a><span class="lineno">    1</span>&#160;</div><div class="line"><a name="l00026"></a><span class="lineno">   26</span>&#160;<span class="preprocessor">#include &lt;stdint.h&gt;</span></div><div class="line"><a name="l00027"></a><span class="lineno">   27</span>&#160;<span class="preprocessor">#include &lt;stdarg.h&gt;</span></div><div class="line"><a name="l00028"></a><span class="lineno">   28</span>&#160;<span class="preprocessor">#include &lt;string.h&gt;</span></div><div class="line"><a name="l00029"></a><span class="lineno">   29</span>&#160;<span class="preprocessor">#include &lt;math.h&gt;</span></div><div class="line"><a name="l00030"></a><span class="lineno">   30</span>&#160;</div><div class="line"><a name="l00031"></a><span class="lineno">   31</span>&#160;<span class="preprocessor">#include &quot;<a class="code" href="user__config_8h.html">user_config.h</a>&quot;</span></div><div class="line"><a name="l00032"></a><span class="lineno">   32</span>&#160;</div><div class="line"><a name="l00033"></a><span class="lineno">   33</span>&#160;<span class="preprocessor">#if DISPLAY</span></div><div class="line"><a name="l00034"></a><span class="lineno">   34</span>&#160;</div><div class="line"><a name="l00035"></a><span class="lineno">   35</span>&#160;<span class="preprocessor">#ifdef XPT2046</span></div><div class="line"><a name="l00036"></a><span class="lineno">   36</span>&#160;<span class="preprocessor">#include &quot;<a class="code" href="xpt2046_8h.html">xpt2046.h</a>&quot;</span></div><div class="line"><a name="l00037"></a><span class="lineno">   37</span>&#160;</div><div class="line"><a name="l00038"></a><span class="lineno">   38</span>&#160;<span class="preprocessor">#include &quot;<a class="code" href="ili9341_8h.html">display/ili9341.h</a>&quot;</span></div><div class="line"><a name="l00039"></a><span class="lineno">   39</span>&#160;</div><div class="line"><a name="l00043"></a><span class="lineno">   43</span>&#160;</div><div class="line"><a name="l00044"></a><span class="lineno">   44</span>&#160;<span class="keyword">extern</span> <a class="code" href="structwindow.html">window</a> *<a class="code" href="ili9341_8c.html#aa55d6901951c7fe057e8d32477b5e122">tft</a>;</div><div class="line"><a name="l00045"></a><span class="lineno">   45</span>&#160;</div><div class="line"><a name="l00046"></a><span class="lineno">   46</span>&#160;<span class="preprocessor">#ifndef XPT2046_CS</span></div><div class="line"><a name="l00047"></a><span class="lineno">   47</span>&#160;<span class="preprocessor">#error You must define the XPT2046 GPIO pin</span></div><div class="line"><a name="l00048"></a><span class="lineno">   48</span>&#160;<span class="preprocessor">#endif</span></div><div class="line"><a name="l00049"></a><span class="lineno">   49</span>&#160;</div><div class="line"><a name="l00052"></a><span class="lineno">   52</span>&#160;</div><div class="line"><a name="l00054"></a><span class="lineno">   54</span>&#160;<a class="code" href="send_8c.html#a435d1572bf3f880d55459d9805097f62">uint32_t</a> XPT2046_clock = -1;</div><div class="line"><a name="l00055"></a><span class="lineno">   55</span>&#160;</div><div class="line"><a name="l00057"></a><span class="lineno">   57</span>&#160;<a class="code" href="struct__xpt2046.html">xpt2046_t</a> xpt2046;</div><div class="line"><a name="l00058"></a><span class="lineno">   58</span>&#160;</div><div class="line"><a name="l00061"></a><span class="lineno">   61</span>&#160;<a class="code" href="cpu_8h.html#ad0fe97585b8891f5e4f2b9a6426330a4">MEMSPACE</a></div><div class="line"><a name="l00062"></a><span class="lineno">   62</span>&#160;<span class="keywordtype">void</span> <a class="code" href="xpt2046_8h.html#acb7288fd027f95ea7db88c6f8c7c2c2a">XPT2046_spi_init</a>(<span class="keywordtype">void</span>)</div><div class="line"><a name="l00063"></a><span class="lineno">   63</span>&#160;{</div><div class="line"><a name="l00064"></a><span class="lineno">   64</span>&#160;    XPT2046_clock = 40;</div><div class="line"><a name="l00065"></a><span class="lineno">   65</span>&#160;    <a class="code" href="hal_8c.html#a9eaae771107e6e01ef45ebe31ca99fdb">chip_select_init</a>(XPT2046_CS);</div><div class="line"><a name="l00066"></a><span class="lineno">   66</span>&#160;    <a class="code" href="xpt2046_8h.html#a73c23d30b0f5adc10232894c18112778">XPT2046_key_flush</a>();</div><div class="line"><a name="l00067"></a><span class="lineno">   67</span>&#160;    xpt2046.<a class="code" href="struct__xpt2046.html#a9730fbc57085ba0f27bf5563fbbce98b">rotation</a> = tft-&gt;<a class="code" href="structwindow.html#afbd48ebcb41e68d0f458dac593578aa8">rotation</a>;</div><div class="line"><a name="l00068"></a><span class="lineno">   68</span>&#160;}</div><div class="line"><a name="l00069"></a><span class="lineno">   69</span>&#160;</div><div class="line"><a name="l00070"></a><span class="lineno">   70</span>&#160;</div><div class="line"><a name="l00072"></a><span class="lineno">   72</span>&#160;<a class="code" href="cpu_8h.html#ad0fe97585b8891f5e4f2b9a6426330a4">MEMSPACE</a></div><div class="line"><a name="l00073"></a><span class="lineno">   73</span>&#160;<span class="keywordtype">void</span> <a class="code" href="xpt2046_8h.html#a73c23d30b0f5adc10232894c18112778">XPT2046_key_flush</a>()</div><div class="line"><a name="l00074"></a><span class="lineno">   74</span>&#160;{</div><div class="line"><a name="l00075"></a><span class="lineno">   75</span>&#160;    xpt2046.<a class="code" href="struct__xpt2046.html#a271e59b1fe899e8d1199f617bd381b15">state</a> = 0;</div><div class="line"><a name="l00076"></a><span class="lineno">   76</span>&#160;    xpt2046.<a class="code" href="struct__xpt2046.html#a7ada38c703d34310580fbdb4625a5190">ms</a> = 0;</div><div class="line"><a name="l00077"></a><span class="lineno">   77</span>&#160;    xpt2046.<a class="code" href="struct__xpt2046.html#ae47d989b6ec543113fc386181ea6d98a">ind</a> = 0;</div><div class="line"><a name="l00078"></a><span class="lineno">   78</span>&#160;    xpt2046.<a class="code" href="struct__xpt2046.html#a8b4e70a2d7a60543902ac8648c986a31">head</a> = 0;</div><div class="line"><a name="l00079"></a><span class="lineno">   79</span>&#160;    xpt2046.<a class="code" href="struct__xpt2046.html#a22287733194e6d32116347f39f77523f">tail</a> = 0;</div><div class="line"><a name="l00080"></a><span class="lineno">   80</span>&#160;}</div><div class="line"><a name="l00081"></a><span class="lineno">   81</span>&#160;</div><div class="line"><a name="l00082"></a><span class="lineno">   82</span>&#160;</div><div class="line"><a name="l00121"></a><span class="lineno">  121</span>&#160;<a class="code" href="send_8c.html#a273cf69d639a59973b6019625df33e30">uint16_t</a> <a class="code" href="xpt2046_8h.html#a1dccf53d8f7692a9ae5f272c7a16f462">XPT2046_read</a>(<a class="code" href="send_8c.html#aba7bc1797add20fe3efdf37ced1182c5">uint8_t</a> cmd)</div><div class="line"><a name="l00125"></a><span class="lineno">  125</span>&#160;{</div><div class="line"><a name="l00126"></a><span class="lineno">  126</span>&#160;    <a class="code" href="send_8c.html#aba7bc1797add20fe3efdf37ced1182c5">uint8_t</a>  buf[3];</div><div class="line"><a name="l00127"></a><span class="lineno">  127</span>&#160;    <a class="code" href="send_8c.html#a273cf69d639a59973b6019625df33e30">uint16_t</a> val;</div><div class="line"><a name="l00128"></a><span class="lineno">  128</span>&#160;    </div><div class="line"><a name="l00129"></a><span class="lineno">  129</span>&#160;    <span class="comment">// First byte to send is the command</span></div><div class="line"><a name="l00130"></a><span class="lineno">  130</span>&#160;    buf[0] = cmd;</div><div class="line"><a name="l00131"></a><span class="lineno">  131</span>&#160;    <span class="comment">// 0 is ignored as a command NOOP, used here to read the reply from the ADC</span></div><div class="line"><a name="l00132"></a><span class="lineno">  132</span>&#160;    buf[1] = 0;</div><div class="line"><a name="l00133"></a><span class="lineno">  133</span>&#160;    buf[2] = 0;</div><div class="line"><a name="l00134"></a><span class="lineno">  134</span>&#160;</div><div class="line"><a name="l00135"></a><span class="lineno">  135</span>&#160;    <a class="code" href="hal_8c.html#acd8b481ba21b545f53061c5ab7ff451e">spi_begin</a>(XPT2046_clock, XPT2046_CS);</div><div class="line"><a name="l00136"></a><span class="lineno">  136</span>&#160;    <span class="comment">// Send three bytes and read the result</span></div><div class="line"><a name="l00137"></a><span class="lineno">  137</span>&#160;    <a class="code" href="hal_8c.html#a79519dd3475dcb68112f162379287e20">spi_TXRX_buffer</a>(buf,3);   </div><div class="line"><a name="l00138"></a><span class="lineno">  138</span>&#160;    <a class="code" href="hal_8c.html#a38fdaad472c50237f3d8821a01cda360">spi_end</a>(XPT2046_CS);</div><div class="line"><a name="l00139"></a><span class="lineno">  139</span>&#160;</div><div class="line"><a name="l00140"></a><span class="lineno">  140</span>&#160;    <span class="comment">// buf[0] - Ignore data read back from the first command byte - is has no valid data</span></div><div class="line"><a name="l00141"></a><span class="lineno">  141</span>&#160;</div><div class="line"><a name="l00142"></a><span class="lineno">  142</span>&#160;    <span class="comment">// Extract the ADC 12 bit reply - ADC result starts one bit AFTER the MSB bit position</span></div><div class="line"><a name="l00143"></a><span class="lineno">  143</span>&#160;    val = buf[1];   <span class="comment">// MSB</span></div><div class="line"><a name="l00144"></a><span class="lineno">  144</span>&#160;    val &lt;&lt;= 8;</div><div class="line"><a name="l00145"></a><span class="lineno">  145</span>&#160;    val |= buf[2];  <span class="comment">// LSB</span></div><div class="line"><a name="l00146"></a><span class="lineno">  146</span>&#160;</div><div class="line"><a name="l00147"></a><span class="lineno">  147</span>&#160;    <span class="comment">// Align 12 bit result to LSB bit position</span></div><div class="line"><a name="l00148"></a><span class="lineno">  148</span>&#160;    val &gt;&gt;= 3;      </div><div class="line"><a name="l00149"></a><span class="lineno">  149</span>&#160;</div><div class="line"><a name="l00150"></a><span class="lineno">  150</span>&#160;    <span class="keywordflow">if</span>(val &lt; 0)</div><div class="line"><a name="l00151"></a><span class="lineno">  151</span>&#160;        val = 0;</div><div class="line"><a name="l00152"></a><span class="lineno">  152</span>&#160;    <span class="keywordflow">if</span>(val &gt;4095)</div><div class="line"><a name="l00153"></a><span class="lineno">  153</span>&#160;        val = 4095;</div><div class="line"><a name="l00154"></a><span class="lineno">  154</span>&#160;    <span class="keywordflow">return</span>(val);</div><div class="line"><a name="l00155"></a><span class="lineno">  155</span>&#160;}</div><div class="line"><a name="l00156"></a><span class="lineno">  156</span>&#160;</div><div class="line"><a name="l00162"></a><span class="lineno">  162</span>&#160;<span class="comment">//MEMSPACE</span></div><div class="line"><a name="l00163"></a><span class="lineno">  163</span>&#160;<span class="keywordtype">int</span> <a class="code" href="xpt2046_8h.html#a02c4dcf896824df15a98acfbe045d19d">XPT2046_xy_raw</a>(<a class="code" href="send_8c.html#a273cf69d639a59973b6019625df33e30">uint16_t</a> *<a class="code" href="cordic_8c.html#a46b4b48ef8c0c01099eb3bcdde8aa8db">X</a>, <a class="code" href="send_8c.html#a273cf69d639a59973b6019625df33e30">uint16_t</a> *<a class="code" href="cordic_8c.html#ab746e677f466f17031e92ed577fc3c15">Y</a>)</div><div class="line"><a name="l00164"></a><span class="lineno">  164</span>&#160;{</div><div class="line"><a name="l00165"></a><span class="lineno">  165</span>&#160;    <span class="keywordtype">int</span> Z1,Z2,<a class="code" href="cordic_8c.html#a3da94d1c83a43c30add6c05fbbe1f194">Z</a>;</div><div class="line"><a name="l00166"></a><span class="lineno">  166</span>&#160;</div><div class="line"><a name="l00167"></a><span class="lineno">  167</span>&#160;    Z1 = <a class="code" href="xpt2046_8h.html#a1dccf53d8f7692a9ae5f272c7a16f462">XPT2046_read</a>(<a class="code" href="xpt2046_8h.html#a1f7063812ae4edbb96165244ee717815">XPT2046_READ_Z1</a>);</div><div class="line"><a name="l00168"></a><span class="lineno">  168</span>&#160;    Z2 = <a class="code" href="xpt2046_8h.html#a1dccf53d8f7692a9ae5f272c7a16f462">XPT2046_read</a>(<a class="code" href="xpt2046_8h.html#aee315feb898d4f6f35389cb3068ad1eb">XPT2046_READ_Z2</a>);</div><div class="line"><a name="l00169"></a><span class="lineno">  169</span>&#160;    <span class="comment">// of the touch pressure</span></div><div class="line"><a name="l00170"></a><span class="lineno">  170</span>&#160;    Z = (4095 - Z2) + Z1;</div><div class="line"><a name="l00171"></a><span class="lineno">  171</span>&#160;    <span class="keywordflow">if</span>(Z &lt; 0)</div><div class="line"><a name="l00172"></a><span class="lineno">  172</span>&#160;        Z = -<a class="code" href="cordic_8c.html#a3da94d1c83a43c30add6c05fbbe1f194">Z</a>;</div><div class="line"><a name="l00173"></a><span class="lineno">  173</span>&#160;    <span class="keywordflow">if</span>(Z &gt; 300)</div><div class="line"><a name="l00174"></a><span class="lineno">  174</span>&#160;    {</div><div class="line"><a name="l00175"></a><span class="lineno">  175</span>&#160;        <span class="keywordflow">switch</span> (tft-&gt;<a class="code" href="structwindow.html#afbd48ebcb41e68d0f458dac593578aa8">rotation</a>)</div><div class="line"><a name="l00176"></a><span class="lineno">  176</span>&#160;        {</div><div class="line"><a name="l00177"></a><span class="lineno">  177</span>&#160;            <span class="keywordflow">case</span> 0:</div><div class="line"><a name="l00178"></a><span class="lineno">  178</span>&#160;                <span class="comment">// reverse X</span></div><div class="line"><a name="l00179"></a><span class="lineno">  179</span>&#160;                xpt2046.<a class="code" href="struct__xpt2046.html#a9730fbc57085ba0f27bf5563fbbce98b">rotation</a> = 0;</div><div class="line"><a name="l00180"></a><span class="lineno">  180</span>&#160;                *X = 4095 - <a class="code" href="xpt2046_8h.html#a1dccf53d8f7692a9ae5f272c7a16f462">XPT2046_read</a>(<a class="code" href="xpt2046_8h.html#aacb7a75fd6c78e1cd4e87fa930654ef6">XPT2046_READ_X</a>);</div><div class="line"><a name="l00181"></a><span class="lineno">  181</span>&#160;                *Y = <a class="code" href="xpt2046_8h.html#a1dccf53d8f7692a9ae5f272c7a16f462">XPT2046_read</a>(<a class="code" href="xpt2046_8h.html#aad6adcb00000ad4cdef14ece5e21bd81">XPT2046_READ_Y</a>);</div><div class="line"><a name="l00182"></a><span class="lineno">  182</span>&#160;                <span class="keywordflow">break</span>;</div><div class="line"><a name="l00183"></a><span class="lineno">  183</span>&#160;</div><div class="line"><a name="l00184"></a><span class="lineno">  184</span>&#160;            <span class="keywordflow">case</span> 1:</div><div class="line"><a name="l00185"></a><span class="lineno">  185</span>&#160;                <span class="comment">// swap X and Y</span></div><div class="line"><a name="l00186"></a><span class="lineno">  186</span>&#160;                xpt2046.<a class="code" href="struct__xpt2046.html#a9730fbc57085ba0f27bf5563fbbce98b">rotation</a> = 1;</div><div class="line"><a name="l00187"></a><span class="lineno">  187</span>&#160;                *X = <a class="code" href="xpt2046_8h.html#a1dccf53d8f7692a9ae5f272c7a16f462">XPT2046_read</a>(<a class="code" href="xpt2046_8h.html#aad6adcb00000ad4cdef14ece5e21bd81">XPT2046_READ_Y</a>);</div><div class="line"><a name="l00188"></a><span class="lineno">  188</span>&#160;                *Y = <a class="code" href="xpt2046_8h.html#a1dccf53d8f7692a9ae5f272c7a16f462">XPT2046_read</a>(<a class="code" href="xpt2046_8h.html#aacb7a75fd6c78e1cd4e87fa930654ef6">XPT2046_READ_X</a>);</div><div class="line"><a name="l00189"></a><span class="lineno">  189</span>&#160;                <span class="keywordflow">break</span>;</div><div class="line"><a name="l00190"></a><span class="lineno">  190</span>&#160;</div><div class="line"><a name="l00191"></a><span class="lineno">  191</span>&#160;            <span class="keywordflow">case</span> 2:</div><div class="line"><a name="l00192"></a><span class="lineno">  192</span>&#160;                <span class="comment">// reverse Y</span></div><div class="line"><a name="l00193"></a><span class="lineno">  193</span>&#160;                xpt2046.<a class="code" href="struct__xpt2046.html#a9730fbc57085ba0f27bf5563fbbce98b">rotation</a> = 2;</div><div class="line"><a name="l00194"></a><span class="lineno">  194</span>&#160;                *X = <a class="code" href="xpt2046_8h.html#a1dccf53d8f7692a9ae5f272c7a16f462">XPT2046_read</a>(<a class="code" href="xpt2046_8h.html#aacb7a75fd6c78e1cd4e87fa930654ef6">XPT2046_READ_X</a>);</div><div class="line"><a name="l00195"></a><span class="lineno">  195</span>&#160;                *Y = 4095 - <a class="code" href="xpt2046_8h.html#a1dccf53d8f7692a9ae5f272c7a16f462">XPT2046_read</a>(<a class="code" href="xpt2046_8h.html#aad6adcb00000ad4cdef14ece5e21bd81">XPT2046_READ_Y</a>);</div><div class="line"><a name="l00196"></a><span class="lineno">  196</span>&#160;                <span class="keywordflow">break</span>;</div><div class="line"><a name="l00197"></a><span class="lineno">  197</span>&#160;</div><div class="line"><a name="l00198"></a><span class="lineno">  198</span>&#160;            <span class="keywordflow">case</span> 3:</div><div class="line"><a name="l00199"></a><span class="lineno">  199</span>&#160;                xpt2046.<a class="code" href="struct__xpt2046.html#a9730fbc57085ba0f27bf5563fbbce98b">rotation</a> = 3;</div><div class="line"><a name="l00200"></a><span class="lineno">  200</span>&#160;                <span class="comment">// swap X and Y and reverse X and Y</span></div><div class="line"><a name="l00201"></a><span class="lineno">  201</span>&#160;                *X = 4095 - <a class="code" href="xpt2046_8h.html#a1dccf53d8f7692a9ae5f272c7a16f462">XPT2046_read</a>(<a class="code" href="xpt2046_8h.html#aad6adcb00000ad4cdef14ece5e21bd81">XPT2046_READ_Y</a>);</div><div class="line"><a name="l00202"></a><span class="lineno">  202</span>&#160;                *Y = 4095 - <a class="code" href="xpt2046_8h.html#a1dccf53d8f7692a9ae5f272c7a16f462">XPT2046_read</a>(<a class="code" href="xpt2046_8h.html#aacb7a75fd6c78e1cd4e87fa930654ef6">XPT2046_READ_X</a>);</div><div class="line"><a name="l00203"></a><span class="lineno">  203</span>&#160;                <span class="keywordflow">break</span>;</div><div class="line"><a name="l00204"></a><span class="lineno">  204</span>&#160;        }</div><div class="line"><a name="l00205"></a><span class="lineno">  205</span>&#160;        <span class="keywordflow">return</span>(1);  <span class="comment">// 1 = touch event</span></div><div class="line"><a name="l00206"></a><span class="lineno">  206</span>&#160;    }</div><div class="line"><a name="l00207"></a><span class="lineno">  207</span>&#160;    <span class="keywordflow">return</span>(0);      <span class="comment">// no touch event</span></div><div class="line"><a name="l00208"></a><span class="lineno">  208</span>&#160;}</div><div class="line"><a name="l00209"></a><span class="lineno">  209</span>&#160;</div><div class="line"><a name="l00210"></a><span class="lineno">  210</span>&#160;</div><div class="line"><a name="l00211"></a><span class="lineno">  211</span>&#160;<span class="preprocessor">#if 0</span></div><div class="line"><a name="l00212"></a><span class="lineno">  212</span>&#160;<a class="code" href="cpu_8h.html#ad0fe97585b8891f5e4f2b9a6426330a4">MEMSPACE</a></div><div class="line"><a name="l00219"></a><span class="lineno">  219</span>&#160;<span class="keywordtype">int</span> <a class="code" href="xpt2046_8h.html#ac22e4f7d0ddbfd16b0c685f90db56656">XPT2046_xy_filtered</a>(<a class="code" href="send_8c.html#a273cf69d639a59973b6019625df33e30">uint16_t</a> *X, <a class="code" href="send_8c.html#a273cf69d639a59973b6019625df33e30">uint16_t</a> *Y)</div><div class="line"><a name="l00220"></a><span class="lineno">  220</span>&#160;{</div><div class="line"><a name="l00221"></a><span class="lineno">  221</span>&#160;    <span class="keywordtype">int</span> XC,YC, XL,YL, XD, YD;</div><div class="line"><a name="l00222"></a><span class="lineno">  222</span>&#160;    <span class="keywordtype">long</span> Xavg,Yavg;</div><div class="line"><a name="l00223"></a><span class="lineno">  223</span>&#160;    <span class="keywordtype">int</span> count;      <span class="comment">// Sample counter - to compute average </span></div><div class="line"><a name="l00224"></a><span class="lineno">  224</span>&#160;</div><div class="line"><a name="l00225"></a><span class="lineno">  225</span>&#160;    Xavg = 0; <span class="comment">// X average</span></div><div class="line"><a name="l00226"></a><span class="lineno">  226</span>&#160;    Yavg = 0; <span class="comment">// Y average</span></div><div class="line"><a name="l00227"></a><span class="lineno">  227</span>&#160;</div><div class="line"><a name="l00228"></a><span class="lineno">  228</span>&#160;    <span class="keywordflow">for</span>(count=0;count&lt;<a class="code" href="xpt2046_8h.html#a0f015f6bedcfd4583ed1133ed6d11963">XPT2046_SAMPLES</a>;++count)</div><div class="line"><a name="l00229"></a><span class="lineno">  229</span>&#160;    {</div><div class="line"><a name="l00230"></a><span class="lineno">  230</span>&#160;        <span class="comment">// X and Y if touched - otherwise 0,0</span></div><div class="line"><a name="l00231"></a><span class="lineno">  231</span>&#160;        <span class="keywordflow">if</span>(!<a class="code" href="xpt2046_8h.html#a02c4dcf896824df15a98acfbe045d19d">XPT2046_xy_raw</a>(X, Y))</div><div class="line"><a name="l00232"></a><span class="lineno">  232</span>&#160;            <span class="keywordflow">break</span>;</div><div class="line"><a name="l00233"></a><span class="lineno">  233</span>&#160;        XC = *<a class="code" href="cordic_8c.html#a46b4b48ef8c0c01099eb3bcdde8aa8db">X</a>;</div><div class="line"><a name="l00234"></a><span class="lineno">  234</span>&#160;        YC = *<a class="code" href="cordic_8c.html#ab746e677f466f17031e92ed577fc3c15">Y</a>;</div><div class="line"><a name="l00235"></a><span class="lineno">  235</span>&#160;        <span class="comment">// Has the permitted peak to peak NOISE maximum been exceeded ?</span></div><div class="line"><a name="l00236"></a><span class="lineno">  236</span>&#160;        <span class="keywordflow">if</span>(count)</div><div class="line"><a name="l00237"></a><span class="lineno">  237</span>&#160;        {</div><div class="line"><a name="l00238"></a><span class="lineno">  238</span>&#160;            XD = XC - XL;</div><div class="line"><a name="l00239"></a><span class="lineno">  239</span>&#160;            <span class="keywordflow">if</span>(XD &lt; 0)</div><div class="line"><a name="l00240"></a><span class="lineno">  240</span>&#160;                XD = -XD;</div><div class="line"><a name="l00241"></a><span class="lineno">  241</span>&#160;            YD = YC - YL;</div><div class="line"><a name="l00242"></a><span class="lineno">  242</span>&#160;            <span class="keywordflow">if</span>(YD &lt; 0)</div><div class="line"><a name="l00243"></a><span class="lineno">  243</span>&#160;                YD = -YD;</div><div class="line"><a name="l00244"></a><span class="lineno">  244</span>&#160;            <span class="keywordflow">if</span>(XD &gt; 20 || YD &gt; 20)</div><div class="line"><a name="l00245"></a><span class="lineno">  245</span>&#160;                <span class="keywordflow">break</span>;</div><div class="line"><a name="l00246"></a><span class="lineno">  246</span>&#160;        }</div><div class="line"><a name="l00247"></a><span class="lineno">  247</span>&#160;</div><div class="line"><a name="l00248"></a><span class="lineno">  248</span>&#160;        <span class="comment">// Update average</span></div><div class="line"><a name="l00249"></a><span class="lineno">  249</span>&#160;        Xavg += XC;</div><div class="line"><a name="l00250"></a><span class="lineno">  250</span>&#160;        Yavg += YC;</div><div class="line"><a name="l00251"></a><span class="lineno">  251</span>&#160;        XL = XC;</div><div class="line"><a name="l00252"></a><span class="lineno">  252</span>&#160;        YL = YC;</div><div class="line"><a name="l00253"></a><span class="lineno">  253</span>&#160;    }   </div><div class="line"><a name="l00254"></a><span class="lineno">  254</span>&#160;</div><div class="line"><a name="l00255"></a><span class="lineno">  255</span>&#160;    <span class="comment">// FIXME testing shows we need at least 2 samples in a row to be ok</span></div><div class="line"><a name="l00256"></a><span class="lineno">  256</span>&#160;    <span class="keywordflow">if</span>(count)</div><div class="line"><a name="l00257"></a><span class="lineno">  257</span>&#160;    {</div><div class="line"><a name="l00258"></a><span class="lineno">  258</span>&#160;        Xavg /= count;</div><div class="line"><a name="l00259"></a><span class="lineno">  259</span>&#160;        Yavg /= count;</div><div class="line"><a name="l00260"></a><span class="lineno">  260</span>&#160;    }</div><div class="line"><a name="l00261"></a><span class="lineno">  261</span>&#160;    *X = (<a class="code" href="send_8c.html#a273cf69d639a59973b6019625df33e30">uint16_t</a>) Xavg;</div><div class="line"><a name="l00262"></a><span class="lineno">  262</span>&#160;    *Y = (<a class="code" href="send_8c.html#a273cf69d639a59973b6019625df33e30">uint16_t</a>) Yavg;</div><div class="line"><a name="l00263"></a><span class="lineno">  263</span>&#160;    <span class="keywordflow">return</span>(count);</div><div class="line"><a name="l00264"></a><span class="lineno">  264</span>&#160;}</div><div class="line"><a name="l00265"></a><span class="lineno">  265</span>&#160;<span class="preprocessor">#else</span></div><div class="line"><a name="l00266"></a><span class="lineno">  266</span>&#160;</div><div class="line"><a name="l00267"></a><span class="lineno">  267</span>&#160;</div><div class="line"><a name="l00274"></a><span class="lineno">  274</span>&#160;<span class="keywordtype">int</span> XPT2046_loop;</div><div class="line"><a name="l00275"></a><span class="lineno">  275</span>&#160;<a class="code" href="cpu_8h.html#ad0fe97585b8891f5e4f2b9a6426330a4">MEMSPACE</a></div><div class="line"><a name="l00276"></a><span class="lineno">  276</span>&#160;<span class="keywordtype">int</span> <a class="code" href="xpt2046_8h.html#abc3bff89c0ea5ee5bb74fa9ce6514789">nearest_run</a>(<span class="keywordtype">int</span> *v, <span class="keywordtype">int</span> size, <span class="keywordtype">int</span> minsamples, <span class="keywordtype">int</span> *count)</div><div class="line"><a name="l00277"></a><span class="lineno">  277</span>&#160;{</div><div class="line"><a name="l00278"></a><span class="lineno">  278</span>&#160;</div><div class="line"><a name="l00279"></a><span class="lineno">  279</span>&#160;    <span class="keywordtype">int</span> i,j;</div><div class="line"><a name="l00280"></a><span class="lineno">  280</span>&#160;    <span class="keywordtype">int</span> val;</div><div class="line"><a name="l00281"></a><span class="lineno">  281</span>&#160;    <span class="keywordtype">int</span> diff,diffavg;</div><div class="line"><a name="l00282"></a><span class="lineno">  282</span>&#160;    <span class="keywordtype">int</span> run;</div><div class="line"><a name="l00283"></a><span class="lineno">  283</span>&#160;    <span class="keywordtype">int</span> <a class="code" href="posix__tests_8c.html#a8d4059ff64356316a5f13d16cdd90fb5">sum</a>;</div><div class="line"><a name="l00284"></a><span class="lineno">  284</span>&#160;    <span class="keywordtype">int</span> noise;</div><div class="line"><a name="l00285"></a><span class="lineno">  285</span>&#160;    <span class="keywordtype">int</span> min_run = 1;</div><div class="line"><a name="l00286"></a><span class="lineno">  286</span>&#160;    <span class="keywordtype">int</span> average = 0;</div><div class="line"><a name="l00287"></a><span class="lineno">  287</span>&#160;    <span class="keywordtype">int</span> min_noise = 65536;</div><div class="line"><a name="l00288"></a><span class="lineno">  288</span>&#160;</div><div class="line"><a name="l00289"></a><span class="lineno">  289</span>&#160;    <span class="keywordflow">for</span>(i=0;i&lt;size;++i)</div><div class="line"><a name="l00290"></a><span class="lineno">  290</span>&#160;    {</div><div class="line"><a name="l00291"></a><span class="lineno">  291</span>&#160;        val = v[i];</div><div class="line"><a name="l00292"></a><span class="lineno">  292</span>&#160;        sum = val;</div><div class="line"><a name="l00293"></a><span class="lineno">  293</span>&#160;        run = 0;</div><div class="line"><a name="l00294"></a><span class="lineno">  294</span>&#160;        noise = 0;</div><div class="line"><a name="l00295"></a><span class="lineno">  295</span>&#160;</div><div class="line"><a name="l00296"></a><span class="lineno">  296</span>&#160;        <span class="keywordflow">for</span>(j=i+1;j&lt;size;++j)</div><div class="line"><a name="l00297"></a><span class="lineno">  297</span>&#160;        {</div><div class="line"><a name="l00298"></a><span class="lineno">  298</span>&#160;            <span class="comment">// compute differences</span></div><div class="line"><a name="l00299"></a><span class="lineno">  299</span>&#160;            diff = v[j] - val;</div><div class="line"><a name="l00300"></a><span class="lineno">  300</span>&#160;            <span class="keywordflow">if</span>(diff &lt; 0)</div><div class="line"><a name="l00301"></a><span class="lineno">  301</span>&#160;                diff = -diff;</div><div class="line"><a name="l00302"></a><span class="lineno">  302</span>&#160;</div><div class="line"><a name="l00303"></a><span class="lineno">  303</span>&#160;            ++run;</div><div class="line"><a name="l00304"></a><span class="lineno">  304</span>&#160;</div><div class="line"><a name="l00305"></a><span class="lineno">  305</span>&#160;            <span class="comment">// this is run+1 sample we have averaged</span></div><div class="line"><a name="l00306"></a><span class="lineno">  306</span>&#160;            sum += v[j];</div><div class="line"><a name="l00307"></a><span class="lineno">  307</span>&#160;</div><div class="line"><a name="l00308"></a><span class="lineno">  308</span>&#160;            noise += diff;</div><div class="line"><a name="l00309"></a><span class="lineno">  309</span>&#160;</div><div class="line"><a name="l00310"></a><span class="lineno">  310</span>&#160;            <span class="comment">// FIXME we want average signal to noise ratio</span></div><div class="line"><a name="l00311"></a><span class="lineno">  311</span>&#160;            <span class="comment">// always favor longer runs if better or equal noise</span></div><div class="line"><a name="l00312"></a><span class="lineno">  312</span>&#160;            <span class="keywordflow">if</span>(run &gt;= minsamples)</div><div class="line"><a name="l00313"></a><span class="lineno">  313</span>&#160;            {</div><div class="line"><a name="l00314"></a><span class="lineno">  314</span>&#160;                <span class="keywordflow">if</span>((noise/run) &lt;= min_noise/min_run)</div><div class="line"><a name="l00315"></a><span class="lineno">  315</span>&#160;                {</div><div class="line"><a name="l00316"></a><span class="lineno">  316</span>&#160;                    min_noise = noise;;</div><div class="line"><a name="l00317"></a><span class="lineno">  317</span>&#160;                    min_run = run;</div><div class="line"><a name="l00318"></a><span class="lineno">  318</span>&#160;                    <span class="comment">// we have run + 1 elements</span></div><div class="line"><a name="l00319"></a><span class="lineno">  319</span>&#160;                    average = sum/(run+1);</div><div class="line"><a name="l00320"></a><span class="lineno">  320</span>&#160;                }</div><div class="line"><a name="l00321"></a><span class="lineno">  321</span>&#160;            }</div><div class="line"><a name="l00322"></a><span class="lineno">  322</span>&#160;        }</div><div class="line"><a name="l00323"></a><span class="lineno">  323</span>&#160;    }</div><div class="line"><a name="l00324"></a><span class="lineno">  324</span>&#160;</div><div class="line"><a name="l00325"></a><span class="lineno">  325</span>&#160;    <span class="comment">// we have run + 1 elements</span></div><div class="line"><a name="l00326"></a><span class="lineno">  326</span>&#160;    *count = min_run+1;</div><div class="line"><a name="l00327"></a><span class="lineno">  327</span>&#160;    <span class="keywordflow">if</span>(min_run &gt;= minsamples)</div><div class="line"><a name="l00328"></a><span class="lineno">  328</span>&#160;    {</div><div class="line"><a name="l00329"></a><span class="lineno">  329</span>&#160;        <span class="keywordflow">return</span>(average);</div><div class="line"><a name="l00330"></a><span class="lineno">  330</span>&#160;    }</div><div class="line"><a name="l00331"></a><span class="lineno">  331</span>&#160;    <span class="keywordflow">return</span>(-1);</div><div class="line"><a name="l00332"></a><span class="lineno">  332</span>&#160;}</div><div class="line"><a name="l00333"></a><span class="lineno">  333</span>&#160;</div><div class="line"><a name="l00340"></a><span class="lineno">  340</span>&#160;<a class="code" href="cpu_8h.html#ad0fe97585b8891f5e4f2b9a6426330a4">MEMSPACE</a></div><div class="line"><a name="l00341"></a><span class="lineno">  341</span>&#160;<span class="keywordtype">int</span> <a class="code" href="xpt2046_8h.html#ac22e4f7d0ddbfd16b0c685f90db56656">XPT2046_xy_filtered</a>(<a class="code" href="send_8c.html#a273cf69d639a59973b6019625df33e30">uint16_t</a> *X, <a class="code" href="send_8c.html#a273cf69d639a59973b6019625df33e30">uint16_t</a> *Y)</div><div class="line"><a name="l00342"></a><span class="lineno">  342</span>&#160;{</div><div class="line"><a name="l00343"></a><span class="lineno">  343</span>&#160;    <span class="keywordtype">int</span> XS[XPT2046_SAMPLES+1];</div><div class="line"><a name="l00344"></a><span class="lineno">  344</span>&#160;    <span class="keywordtype">int</span> YS[XPT2046_SAMPLES+1];</div><div class="line"><a name="l00345"></a><span class="lineno">  345</span>&#160;    <span class="keywordtype">int</span> Xavg,Yavg;</div><div class="line"><a name="l00346"></a><span class="lineno">  346</span>&#160;    <span class="keywordtype">int</span> xcount,ycount;</div><div class="line"><a name="l00347"></a><span class="lineno">  347</span>&#160;</div><div class="line"><a name="l00348"></a><span class="lineno">  348</span>&#160;    <span class="keywordtype">int</span> i;</div><div class="line"><a name="l00349"></a><span class="lineno">  349</span>&#160;    <span class="keywordflow">for</span>(i=0;i&lt;<a class="code" href="xpt2046_8h.html#a0f015f6bedcfd4583ed1133ed6d11963">XPT2046_SAMPLES</a>;++i)</div><div class="line"><a name="l00350"></a><span class="lineno">  350</span>&#160;    {</div><div class="line"><a name="l00351"></a><span class="lineno">  351</span>&#160;        <span class="comment">// X and Y if touched - otherwise 0,0</span></div><div class="line"><a name="l00352"></a><span class="lineno">  352</span>&#160;        <span class="keywordflow">if</span>(!<a class="code" href="xpt2046_8h.html#a02c4dcf896824df15a98acfbe045d19d">XPT2046_xy_raw</a>(X, Y))</div><div class="line"><a name="l00353"></a><span class="lineno">  353</span>&#160;            <span class="keywordflow">break</span>;</div><div class="line"><a name="l00354"></a><span class="lineno">  354</span>&#160;        XS[i] = *<a class="code" href="cordic_8c.html#a46b4b48ef8c0c01099eb3bcdde8aa8db">X</a>;</div><div class="line"><a name="l00355"></a><span class="lineno">  355</span>&#160;        YS[i] = *<a class="code" href="cordic_8c.html#ab746e677f466f17031e92ed577fc3c15">Y</a>;</div><div class="line"><a name="l00356"></a><span class="lineno">  356</span>&#160;    }</div><div class="line"><a name="l00357"></a><span class="lineno">  357</span>&#160;</div><div class="line"><a name="l00358"></a><span class="lineno">  358</span>&#160;    <span class="keywordflow">if</span>(i &gt;= 3)</div><div class="line"><a name="l00359"></a><span class="lineno">  359</span>&#160;    {</div><div class="line"><a name="l00360"></a><span class="lineno">  360</span>&#160;        Xavg = <a class="code" href="xpt2046_8h.html#abc3bff89c0ea5ee5bb74fa9ce6514789">nearest_run</a>((<span class="keywordtype">int</span> *) &amp;XS, i, 3, &amp;xcount);</div><div class="line"><a name="l00361"></a><span class="lineno">  361</span>&#160;        Yavg = <a class="code" href="xpt2046_8h.html#abc3bff89c0ea5ee5bb74fa9ce6514789">nearest_run</a>((<span class="keywordtype">int</span> *) &amp;YS, i, 3, &amp;ycount);</div><div class="line"><a name="l00362"></a><span class="lineno">  362</span>&#160;</div><div class="line"><a name="l00363"></a><span class="lineno">  363</span>&#160;        <span class="keywordflow">if</span>(Xavg &gt;= 0 &amp;&amp; Yavg &gt;= 0)</div><div class="line"><a name="l00364"></a><span class="lineno">  364</span>&#160;        {   </div><div class="line"><a name="l00365"></a><span class="lineno">  365</span>&#160;            *X = (<a class="code" href="send_8c.html#a273cf69d639a59973b6019625df33e30">uint16_t</a>) Xavg;</div><div class="line"><a name="l00366"></a><span class="lineno">  366</span>&#160;            *Y = (<a class="code" href="send_8c.html#a273cf69d639a59973b6019625df33e30">uint16_t</a>) Yavg;</div><div class="line"><a name="l00367"></a><span class="lineno">  367</span>&#160;<span class="preprocessor">    #if XPT2046_DEBUG &amp; 2</span></div><div class="line"><a name="l00368"></a><span class="lineno">  368</span>&#160;            <a class="code" href="mathio_8h.html#ad6078f8da2d30ecaef99e0c2d250c0c8">printf</a>(<span class="stringliteral">&quot;X:%4d, Y:%4d, XN:%2d, YN:%d\n&quot;</span>,</div><div class="line"><a name="l00369"></a><span class="lineno">  369</span>&#160;                (<span class="keywordtype">int</span>)Xavg, (<span class="keywordtype">int</span>)Yavg, (<span class="keywordtype">int</span>)xcount,(<span class="keywordtype">int</span>)ycount);</div><div class="line"><a name="l00370"></a><span class="lineno">  370</span>&#160;<span class="preprocessor">    #endif</span></div><div class="line"><a name="l00371"></a><span class="lineno">  371</span>&#160;            <span class="keywordflow">return</span>(i);</div><div class="line"><a name="l00372"></a><span class="lineno">  372</span>&#160;        }</div><div class="line"><a name="l00373"></a><span class="lineno">  373</span>&#160;    }</div><div class="line"><a name="l00374"></a><span class="lineno">  374</span>&#160;    <span class="keywordflow">return</span>(0);</div><div class="line"><a name="l00375"></a><span class="lineno">  375</span>&#160;}</div><div class="line"><a name="l00376"></a><span class="lineno">  376</span>&#160;</div><div class="line"><a name="l00377"></a><span class="lineno">  377</span>&#160;</div><div class="line"><a name="l00378"></a><span class="lineno">  378</span>&#160;<span class="preprocessor">#endif</span></div><div class="line"><a name="l00379"></a><span class="lineno">  379</span>&#160;</div><div class="line"><a name="l00385"></a><span class="lineno">  385</span>&#160;<span class="keywordtype">int</span> XPT2046_loop;</div><div class="line"><a name="l00386"></a><span class="lineno">  386</span>&#160;<a class="code" href="cpu_8h.html#ad0fe97585b8891f5e4f2b9a6426330a4">MEMSPACE</a></div><div class="line"><a name="l00387"></a><span class="lineno">  387</span>&#160;<span class="keywordtype">int</span> <a class="code" href="xpt2046_8h.html#a16726a7a1ffb7ff25c3a2601b578cc19">XPT2046_xy_filtered_test</a>(<a class="code" href="send_8c.html#a273cf69d639a59973b6019625df33e30">uint16_t</a> *X, <a class="code" href="send_8c.html#a273cf69d639a59973b6019625df33e30">uint16_t</a> *Y)</div><div class="line"><a name="l00388"></a><span class="lineno">  388</span>&#160;{</div><div class="line"><a name="l00389"></a><span class="lineno">  389</span>&#160;</div><div class="line"><a name="l00390"></a><span class="lineno">  390</span>&#160;    <span class="keywordtype">int</span> T;</div><div class="line"><a name="l00391"></a><span class="lineno">  391</span>&#160;    XPT2046_loop = 0;</div><div class="line"><a name="l00392"></a><span class="lineno">  392</span>&#160;    <span class="keywordflow">while</span>(1)</div><div class="line"><a name="l00393"></a><span class="lineno">  393</span>&#160;    {</div><div class="line"><a name="l00394"></a><span class="lineno">  394</span>&#160;        T = <a class="code" href="xpt2046_8h.html#ac22e4f7d0ddbfd16b0c685f90db56656">XPT2046_xy_filtered</a>(X, Y);</div><div class="line"><a name="l00395"></a><span class="lineno">  395</span>&#160;        XPT2046_loop += T;</div><div class="line"><a name="l00396"></a><span class="lineno">  396</span>&#160;        <span class="keywordflow">if</span>(!T)</div><div class="line"><a name="l00397"></a><span class="lineno">  397</span>&#160;            <span class="keywordflow">return</span>(0);</div><div class="line"><a name="l00398"></a><span class="lineno">  398</span>&#160;        <span class="keywordflow">if</span>(T &gt;= XPT2046_SAMPLES/2)</div><div class="line"><a name="l00399"></a><span class="lineno">  399</span>&#160;            <span class="keywordflow">return</span>(1);</div><div class="line"><a name="l00400"></a><span class="lineno">  400</span>&#160;    }</div><div class="line"><a name="l00401"></a><span class="lineno">  401</span>&#160;}</div><div class="line"><a name="l00402"></a><span class="lineno">  402</span>&#160;</div><div class="line"><a name="l00403"></a><span class="lineno">  403</span>&#160;</div><div class="line"><a name="l00407"></a><span class="lineno">  407</span>&#160;<a class="code" href="cpu_8h.html#ad0fe97585b8891f5e4f2b9a6426330a4">MEMSPACE</a></div><div class="line"><a name="l00408"></a><span class="lineno">  408</span>&#160;<span class="keywordtype">void</span> <a class="code" href="xpt2046_8h.html#ab0f1cf1130e264b4181a0b525c9be839">XPT2046_task</a>()</div><div class="line"><a name="l00409"></a><span class="lineno">  409</span>&#160;{</div><div class="line"><a name="l00410"></a><span class="lineno">  410</span>&#160;    <a class="code" href="send_8c.html#a273cf69d639a59973b6019625df33e30">uint16_t</a> <a class="code" href="cordic_8c.html#a46b4b48ef8c0c01099eb3bcdde8aa8db">X</a>,<a class="code" href="cordic_8c.html#ab746e677f466f17031e92ed577fc3c15">Y</a>;</div><div class="line"><a name="l00411"></a><span class="lineno">  411</span>&#160;    <span class="keywordtype">int</span> T;</div><div class="line"><a name="l00412"></a><span class="lineno">  412</span>&#160;</div><div class="line"><a name="l00413"></a><span class="lineno">  413</span>&#160;    T = <a class="code" href="xpt2046_8h.html#ac22e4f7d0ddbfd16b0c685f90db56656">XPT2046_xy_filtered</a>((<a class="code" href="send_8c.html#a273cf69d639a59973b6019625df33e30">uint16_t</a> *)&amp;X, (<a class="code" href="send_8c.html#a273cf69d639a59973b6019625df33e30">uint16_t</a> *)&amp;Y);</div><div class="line"><a name="l00414"></a><span class="lineno">  414</span>&#160;    </div><div class="line"><a name="l00415"></a><span class="lineno">  415</span>&#160;    <span class="comment">// Key debounce state machine</span></div><div class="line"><a name="l00416"></a><span class="lineno">  416</span>&#160;    <span class="keywordflow">switch</span>(xpt2046.<a class="code" href="struct__xpt2046.html#a271e59b1fe899e8d1199f617bd381b15">state</a>) </div><div class="line"><a name="l00417"></a><span class="lineno">  417</span>&#160;    {</div><div class="line"><a name="l00418"></a><span class="lineno">  418</span>&#160;        <span class="comment">// Full init</span></div><div class="line"><a name="l00419"></a><span class="lineno">  419</span>&#160;        <span class="keywordflow">case</span> 0:                 </div><div class="line"><a name="l00420"></a><span class="lineno">  420</span>&#160;            xpt2046.<a class="code" href="struct__xpt2046.html#a271e59b1fe899e8d1199f617bd381b15">state</a> = 1;</div><div class="line"><a name="l00421"></a><span class="lineno">  421</span>&#160;            xpt2046.<a class="code" href="struct__xpt2046.html#a7ada38c703d34310580fbdb4625a5190">ms</a> = 0;</div><div class="line"><a name="l00422"></a><span class="lineno">  422</span>&#160;            xpt2046.<a class="code" href="struct__xpt2046.html#ae47d989b6ec543113fc386181ea6d98a">ind</a> = 0;</div><div class="line"><a name="l00423"></a><span class="lineno">  423</span>&#160;            xpt2046.<a class="code" href="struct__xpt2046.html#a8b4e70a2d7a60543902ac8648c986a31">head</a> = 0;</div><div class="line"><a name="l00424"></a><span class="lineno">  424</span>&#160;            xpt2046.<a class="code" href="struct__xpt2046.html#a22287733194e6d32116347f39f77523f">tail</a> = 0;</div><div class="line"><a name="l00425"></a><span class="lineno">  425</span>&#160;            <span class="comment">// Fall through to state 1</span></div><div class="line"><a name="l00426"></a><span class="lineno">  426</span>&#160;        <span class="keywordflow">case</span> 1:</div><div class="line"><a name="l00427"></a><span class="lineno">  427</span>&#160;            <span class="comment">// FIXME this can be a lower count for a button as we are not drawing here</span></div><div class="line"><a name="l00428"></a><span class="lineno">  428</span>&#160;            <span class="keywordflow">if</span>(T)   <span class="comment">// key is down and noise level is in range</span></div><div class="line"><a name="l00429"></a><span class="lineno">  429</span>&#160;            {</div><div class="line"><a name="l00430"></a><span class="lineno">  430</span>&#160;                <span class="comment">// wait for key down debounce time before taking a sample</span></div><div class="line"><a name="l00431"></a><span class="lineno">  431</span>&#160;                <span class="keywordflow">if</span>(++xpt2046.<a class="code" href="struct__xpt2046.html#a7ada38c703d34310580fbdb4625a5190">ms</a> &lt; <a class="code" href="xpt2046_8h.html#a6e35379ae648fa9db798144a9902f8ec">XPT2046_DEBOUNCE</a>)     </div><div class="line"><a name="l00432"></a><span class="lineno">  432</span>&#160;                    <span class="keywordflow">break</span>;</div><div class="line"><a name="l00433"></a><span class="lineno">  433</span>&#160;</div><div class="line"><a name="l00434"></a><span class="lineno">  434</span>&#160;                <span class="keywordflow">if</span>(xpt2046.<a class="code" href="struct__xpt2046.html#ae47d989b6ec543113fc386181ea6d98a">ind</a> &lt; <a class="code" href="xpt2046_8h.html#abce5dd412f3f040208dab108718fb875">XPT2046_EVENTS</a> )</div><div class="line"><a name="l00435"></a><span class="lineno">  435</span>&#160;                {</div><div class="line"><a name="l00436"></a><span class="lineno">  436</span>&#160;                    xpt2046.<a class="code" href="struct__xpt2046.html#ac3f7953dda5a05a52276892bee461a29">XQ</a>[xpt2046.<a class="code" href="struct__xpt2046.html#a8b4e70a2d7a60543902ac8648c986a31">head</a>] = <a class="code" href="cordic_8c.html#a46b4b48ef8c0c01099eb3bcdde8aa8db">X</a>;</div><div class="line"><a name="l00437"></a><span class="lineno">  437</span>&#160;                    xpt2046.<a class="code" href="struct__xpt2046.html#a0a1b0401066322d653135eb8db55d198">YQ</a>[xpt2046.<a class="code" href="struct__xpt2046.html#a8b4e70a2d7a60543902ac8648c986a31">head</a>] = <a class="code" href="cordic_8c.html#ab746e677f466f17031e92ed577fc3c15">Y</a>;</div><div class="line"><a name="l00438"></a><span class="lineno">  438</span>&#160;                    <span class="keywordflow">if</span>(++xpt2046.<a class="code" href="struct__xpt2046.html#a8b4e70a2d7a60543902ac8648c986a31">head</a> &gt;= <a class="code" href="xpt2046_8h.html#abce5dd412f3f040208dab108718fb875">XPT2046_EVENTS</a>)</div><div class="line"><a name="l00439"></a><span class="lineno">  439</span>&#160;                        xpt2046.<a class="code" href="struct__xpt2046.html#a8b4e70a2d7a60543902ac8648c986a31">head</a> = 0;</div><div class="line"><a name="l00440"></a><span class="lineno">  440</span>&#160;                    xpt2046.<a class="code" href="struct__xpt2046.html#ae47d989b6ec543113fc386181ea6d98a">ind</a>++;</div><div class="line"><a name="l00441"></a><span class="lineno">  441</span>&#160;                    xpt2046.<a class="code" href="struct__xpt2046.html#a271e59b1fe899e8d1199f617bd381b15">state</a> = 2;</div><div class="line"><a name="l00442"></a><span class="lineno">  442</span>&#160;                    xpt2046.<a class="code" href="struct__xpt2046.html#a7ada38c703d34310580fbdb4625a5190">ms</a> = 0;</div><div class="line"><a name="l00443"></a><span class="lineno">  443</span>&#160;                }</div><div class="line"><a name="l00444"></a><span class="lineno">  444</span>&#160;                <span class="keywordflow">else</span></div><div class="line"><a name="l00445"></a><span class="lineno">  445</span>&#160;                {</div><div class="line"><a name="l00446"></a><span class="lineno">  446</span>&#160;                    xpt2046.<a class="code" href="struct__xpt2046.html#a7ada38c703d34310580fbdb4625a5190">ms</a> = 0;</div><div class="line"><a name="l00447"></a><span class="lineno">  447</span>&#160;                }</div><div class="line"><a name="l00448"></a><span class="lineno">  448</span>&#160;            }   <span class="comment">// if (T)</span></div><div class="line"><a name="l00449"></a><span class="lineno">  449</span>&#160;            <span class="keywordflow">else</span>    <span class="comment">// Restart timer and wait for touch debounce time</span></div><div class="line"><a name="l00450"></a><span class="lineno">  450</span>&#160;            {</div><div class="line"><a name="l00451"></a><span class="lineno">  451</span>&#160;                xpt2046.<a class="code" href="struct__xpt2046.html#a7ada38c703d34310580fbdb4625a5190">ms</a> = 0;</div><div class="line"><a name="l00452"></a><span class="lineno">  452</span>&#160;            }</div><div class="line"><a name="l00453"></a><span class="lineno">  453</span>&#160;            <span class="keywordflow">break</span>;</div><div class="line"><a name="l00454"></a><span class="lineno">  454</span>&#160;</div><div class="line"><a name="l00455"></a><span class="lineno">  455</span>&#160;            <span class="comment">// Wait for touch release debounce time</span></div><div class="line"><a name="l00456"></a><span class="lineno">  456</span>&#160;        <span class="keywordflow">case</span> 2:                 </div><div class="line"><a name="l00457"></a><span class="lineno">  457</span>&#160;            <span class="comment">// Released ?</span></div><div class="line"><a name="l00458"></a><span class="lineno">  458</span>&#160;            <span class="keywordflow">if</span>(T == 0)</div><div class="line"><a name="l00459"></a><span class="lineno">  459</span>&#160;            {</div><div class="line"><a name="l00460"></a><span class="lineno">  460</span>&#160;                <span class="comment">// Debounce release time - valid key depress cycle done</span></div><div class="line"><a name="l00461"></a><span class="lineno">  461</span>&#160;                <span class="keywordflow">if</span>(++xpt2046.<a class="code" href="struct__xpt2046.html#a7ada38c703d34310580fbdb4625a5190">ms</a> &gt;= <a class="code" href="xpt2046_8h.html#a6e35379ae648fa9db798144a9902f8ec">XPT2046_DEBOUNCE</a>) </div><div class="line"><a name="l00462"></a><span class="lineno">  462</span>&#160;                {</div><div class="line"><a name="l00463"></a><span class="lineno">  463</span>&#160;                    xpt2046.<a class="code" href="struct__xpt2046.html#a7ada38c703d34310580fbdb4625a5190">ms</a> = 0;</div><div class="line"><a name="l00464"></a><span class="lineno">  464</span>&#160;                    xpt2046.<a class="code" href="struct__xpt2046.html#a271e59b1fe899e8d1199f617bd381b15">state</a> = 1;</div><div class="line"><a name="l00465"></a><span class="lineno">  465</span>&#160;                }</div><div class="line"><a name="l00466"></a><span class="lineno">  466</span>&#160;            }</div><div class="line"><a name="l00467"></a><span class="lineno">  467</span>&#160;            <span class="keywordflow">else</span>    <span class="comment">// Still depressed</span></div><div class="line"><a name="l00468"></a><span class="lineno">  468</span>&#160;            {</div><div class="line"><a name="l00469"></a><span class="lineno">  469</span>&#160;                xpt2046.<a class="code" href="struct__xpt2046.html#a7ada38c703d34310580fbdb4625a5190">ms</a> = 0;</div><div class="line"><a name="l00470"></a><span class="lineno">  470</span>&#160;            }</div><div class="line"><a name="l00471"></a><span class="lineno">  471</span>&#160;            <span class="keywordflow">break</span>;</div><div class="line"><a name="l00472"></a><span class="lineno">  472</span>&#160;</div><div class="line"><a name="l00473"></a><span class="lineno">  473</span>&#160;</div><div class="line"><a name="l00474"></a><span class="lineno">  474</span>&#160;            <span class="comment">// Error INIT</span></div><div class="line"><a name="l00475"></a><span class="lineno">  475</span>&#160;        <span class="keywordflow">default</span>:</div><div class="line"><a name="l00476"></a><span class="lineno">  476</span>&#160;            xpt2046.<a class="code" href="struct__xpt2046.html#a271e59b1fe899e8d1199f617bd381b15">state</a> = 0;</div><div class="line"><a name="l00477"></a><span class="lineno">  477</span>&#160;            <span class="keywordflow">break</span>;</div><div class="line"><a name="l00478"></a><span class="lineno">  478</span>&#160;    }</div><div class="line"><a name="l00479"></a><span class="lineno">  479</span>&#160;}</div><div class="line"><a name="l00480"></a><span class="lineno">  480</span>&#160;</div><div class="line"><a name="l00481"></a><span class="lineno">  481</span>&#160;</div><div class="line"><a name="l00486"></a><span class="lineno">  486</span>&#160;<a class="code" href="cpu_8h.html#ad0fe97585b8891f5e4f2b9a6426330a4">MEMSPACE</a></div><div class="line"><a name="l00487"></a><span class="lineno">  487</span>&#160;<span class="keywordtype">int</span> <a class="code" href="xpt2046_8h.html#a69fc6431a2058d4fd8c26af6547cfae5">XPT2046_key</a>(<a class="code" href="send_8c.html#a273cf69d639a59973b6019625df33e30">uint16_t</a> *X, <a class="code" href="send_8c.html#a273cf69d639a59973b6019625df33e30">uint16_t</a> *Y)</div><div class="line"><a name="l00488"></a><span class="lineno">  488</span>&#160;{</div><div class="line"><a name="l00489"></a><span class="lineno">  489</span>&#160;    <a class="code" href="xpt2046_8h.html#ab0f1cf1130e264b4181a0b525c9be839">XPT2046_task</a>();</div><div class="line"><a name="l00490"></a><span class="lineno">  490</span>&#160;    <span class="keywordflow">if</span>(xpt2046.<a class="code" href="struct__xpt2046.html#ae47d989b6ec543113fc386181ea6d98a">ind</a> &gt; 0)</div><div class="line"><a name="l00491"></a><span class="lineno">  491</span>&#160;    {</div><div class="line"><a name="l00492"></a><span class="lineno">  492</span>&#160;        *X = (<a class="code" href="send_8c.html#a273cf69d639a59973b6019625df33e30">uint16_t</a>) xpt2046.<a class="code" href="struct__xpt2046.html#ac3f7953dda5a05a52276892bee461a29">XQ</a>[xpt2046.<a class="code" href="struct__xpt2046.html#a22287733194e6d32116347f39f77523f">tail</a>];</div><div class="line"><a name="l00493"></a><span class="lineno">  493</span>&#160;        *Y = (<a class="code" href="send_8c.html#a273cf69d639a59973b6019625df33e30">uint16_t</a>) xpt2046.<a class="code" href="struct__xpt2046.html#a0a1b0401066322d653135eb8db55d198">YQ</a>[xpt2046.<a class="code" href="struct__xpt2046.html#a22287733194e6d32116347f39f77523f">tail</a>];</div><div class="line"><a name="l00494"></a><span class="lineno">  494</span>&#160;        <span class="keywordflow">if</span>(++xpt2046.<a class="code" href="struct__xpt2046.html#a22287733194e6d32116347f39f77523f">tail</a> &gt;= <a class="code" href="xpt2046_8h.html#abce5dd412f3f040208dab108718fb875">XPT2046_EVENTS</a>)</div><div class="line"><a name="l00495"></a><span class="lineno">  495</span>&#160;            xpt2046.<a class="code" href="struct__xpt2046.html#a22287733194e6d32116347f39f77523f">tail</a> = 0;</div><div class="line"><a name="l00496"></a><span class="lineno">  496</span>&#160;        xpt2046.<a class="code" href="struct__xpt2046.html#ae47d989b6ec543113fc386181ea6d98a">ind</a>--;</div><div class="line"><a name="l00497"></a><span class="lineno">  497</span>&#160;        <span class="keywordflow">return</span>(1);</div><div class="line"><a name="l00498"></a><span class="lineno">  498</span>&#160;    }</div><div class="line"><a name="l00499"></a><span class="lineno">  499</span>&#160;    *X = 0;</div><div class="line"><a name="l00500"></a><span class="lineno">  500</span>&#160;    *Y = 0;</div><div class="line"><a name="l00501"></a><span class="lineno">  501</span>&#160;    <span class="keywordflow">return</span>(0);</div><div class="line"><a name="l00502"></a><span class="lineno">  502</span>&#160;}</div><div class="line"><a name="l00503"></a><span class="lineno">  503</span>&#160;</div><div class="line"><a name="l00504"></a><span class="lineno">  504</span>&#160;<span class="comment">// ===========================================================================</span></div><div class="line"><a name="l00505"></a><span class="lineno">  505</span>&#160;</div><div class="line"><a name="l00506"></a><span class="lineno">  506</span>&#160;<span class="comment">// </span></div><div class="line"><a name="l00507"></a><span class="lineno">  507</span>&#160;<span class="preprocessor">#ifdef ESP8266</span></div><div class="line"><a name="l00508"></a><span class="lineno">  508</span>&#160;<span class="keywordtype">int</span> __errno;</div><div class="line"><a name="l00509"></a><span class="lineno">  509</span>&#160;<span class="preprocessor">#endif</span></div><div class="line"><a name="l00510"></a><span class="lineno">  510</span>&#160;</div><div class="line"><a name="l00518"></a><span class="lineno">  518</span>&#160;<a class="code" href="cpu_8h.html#ad0fe97585b8891f5e4f2b9a6426330a4">MEMSPACE</a></div><div class="line"><a name="l00519"></a><span class="lineno">  519</span>&#160;<span class="keywordtype">int</span> <a class="code" href="xpt2046_8h.html#a3c3571dfe466884bea2a25234aca83ad">sdev</a>(<a class="code" href="send_8c.html#a273cf69d639a59973b6019625df33e30">uint16_t</a> *samples, <span class="keywordtype">int</span> size, <a class="code" href="struct__sdev.html">sdev_t</a> *Z) </div><div class="line"><a name="l00520"></a><span class="lineno">  520</span>&#160;{</div><div class="line"><a name="l00521"></a><span class="lineno">  521</span>&#160;    <span class="keywordtype">int</span> i;</div><div class="line"><a name="l00522"></a><span class="lineno">  522</span>&#160;    <span class="keywordtype">float</span> val, delta, <a class="code" href="posix__tests_8c.html#a8d4059ff64356316a5f13d16cdd90fb5">sum</a>, sqsum;</div><div class="line"><a name="l00523"></a><span class="lineno">  523</span>&#160;</div><div class="line"><a name="l00524"></a><span class="lineno">  524</span>&#160;    Z-&gt;<a class="code" href="struct__sdev.html#af6ec6d9f07c677d6a25c12c128a60d21">min</a> = ~0;</div><div class="line"><a name="l00525"></a><span class="lineno">  525</span>&#160;    Z-&gt;<a class="code" href="struct__sdev.html#acee505856b840e75edf6af7da7bdaad3">max</a> = 0;</div><div class="line"><a name="l00526"></a><span class="lineno">  526</span>&#160;</div><div class="line"><a name="l00527"></a><span class="lineno">  527</span>&#160;<span class="comment">// error in sample size ?</span></div><div class="line"><a name="l00528"></a><span class="lineno">  528</span>&#160;    <span class="keywordflow">if</span>(size &lt; 2)</div><div class="line"><a name="l00529"></a><span class="lineno">  529</span>&#160;        <span class="keywordflow">return</span>(0);</div><div class="line"><a name="l00530"></a><span class="lineno">  530</span>&#160;</div><div class="line"><a name="l00531"></a><span class="lineno">  531</span>&#160;    sum = 0.0;</div><div class="line"><a name="l00532"></a><span class="lineno">  532</span>&#160;    <span class="keywordflow">for</span>(i=0; i&lt;size ; i++) {</div><div class="line"><a name="l00533"></a><span class="lineno">  533</span>&#160;        val = samples[i];</div><div class="line"><a name="l00534"></a><span class="lineno">  534</span>&#160;        <span class="keywordflow">if</span>(Z-&gt;<a class="code" href="struct__sdev.html#af6ec6d9f07c677d6a25c12c128a60d21">min</a> &gt; val)</div><div class="line"><a name="l00535"></a><span class="lineno">  535</span>&#160;            Z-&gt;<a class="code" href="struct__sdev.html#af6ec6d9f07c677d6a25c12c128a60d21">min</a> = val;</div><div class="line"><a name="l00536"></a><span class="lineno">  536</span>&#160;        <span class="keywordflow">if</span>(Z-&gt;<a class="code" href="struct__sdev.html#acee505856b840e75edf6af7da7bdaad3">max</a> &lt; val)</div><div class="line"><a name="l00537"></a><span class="lineno">  537</span>&#160;            Z-&gt;<a class="code" href="struct__sdev.html#acee505856b840e75edf6af7da7bdaad3">max</a> = val;</div><div class="line"><a name="l00538"></a><span class="lineno">  538</span>&#160;        sum += val;</div><div class="line"><a name="l00539"></a><span class="lineno">  539</span>&#160;    }</div><div class="line"><a name="l00540"></a><span class="lineno">  540</span>&#160;    Z-&gt;<a class="code" href="struct__sdev.html#a2bd0cf80fd334fabaac9100a2538bcb5">mean</a> = sum / (float) size;</div><div class="line"><a name="l00541"></a><span class="lineno">  541</span>&#160;    sqsum = 0.0;</div><div class="line"><a name="l00542"></a><span class="lineno">  542</span>&#160;    <span class="keywordflow">for</span>(i=0;i&lt;size;++i) {</div><div class="line"><a name="l00543"></a><span class="lineno">  543</span>&#160;        val = samples[i];</div><div class="line"><a name="l00544"></a><span class="lineno">  544</span>&#160;        <span class="keywordflow">if</span>(val &lt; 0 || val &gt; 4095)</div><div class="line"><a name="l00545"></a><span class="lineno">  545</span>&#160;            <span class="keywordflow">continue</span>;   <span class="comment">// reject</span></div><div class="line"><a name="l00546"></a><span class="lineno">  546</span>&#160;        delta = val - Z-&gt;<a class="code" href="struct__sdev.html#a2bd0cf80fd334fabaac9100a2538bcb5">mean</a>;</div><div class="line"><a name="l00547"></a><span class="lineno">  547</span>&#160;        sqsum += (delta * delta);</div><div class="line"><a name="l00548"></a><span class="lineno">  548</span>&#160;    }</div><div class="line"><a name="l00549"></a><span class="lineno">  549</span>&#160;    val = sqsum / (float) (i - 1);</div><div class="line"><a name="l00550"></a><span class="lineno">  550</span>&#160;    Z-&gt;<a class="code" href="struct__sdev.html#a053a14f9e4bd729ce23aafdb1e69e48a">sdev</a> = sqrt(val);</div><div class="line"><a name="l00551"></a><span class="lineno">  551</span>&#160;    <span class="keywordflow">return</span>(1);</div><div class="line"><a name="l00552"></a><span class="lineno">  552</span>&#160;}</div><div class="line"><a name="l00553"></a><span class="lineno">  553</span>&#160;</div><div class="line"><a name="l00554"></a><span class="lineno">  554</span>&#160;<span class="preprocessor">#endif // XPT2046</span></div><div class="line"><a name="l00555"></a><span class="lineno">  555</span>&#160;<span class="preprocessor">#endif // DISPLAY</span></div><div class="ttc" id="xpt2046_8h_html_abc3bff89c0ea5ee5bb74fa9ce6514789"><div class="ttname"><a href="xpt2046_8h.html#abc3bff89c0ea5ee5bb74fa9ce6514789">nearest_run</a></div><div class="ttdeci">MEMSPACE int nearest_run(int *v, int size, int minsamples, int *count)</div></div>
<div class="ttc" id="struct__xpt2046_html_a7ada38c703d34310580fbdb4625a5190"><div class="ttname"><a href="struct__xpt2046.html#a7ada38c703d34310580fbdb4625a5190">_xpt2046::ms</a></div><div class="ttdeci">int ms</div><div class="ttdef"><b>Definition:</b> <a href="xpt2046_8h_source.html#l00055">xpt2046.h:55</a></div></div>
<div class="ttc" id="send_8c_html_a273cf69d639a59973b6019625df33e30"><div class="ttname"><a href="send_8c.html#a273cf69d639a59973b6019625df33e30">uint16_t</a></div><div class="ttdeci">unsigned short uint16_t</div><div class="ttdef"><b>Definition:</b> <a href="send_8c_source.html#l00018">send.c:18</a></div></div>
<div class="ttc" id="struct__sdev_html_acee505856b840e75edf6af7da7bdaad3"><div class="ttname"><a href="struct__sdev.html#acee505856b840e75edf6af7da7bdaad3">_sdev::max</a></div><div class="ttdeci">uint16_t max</div><div class="ttdef"><b>Definition:</b> <a href="xpt2046_8h_source.html#l00075">xpt2046.h:75</a></div></div>
<div class="ttc" id="xpt2046_8h_html_abce5dd412f3f040208dab108718fb875"><div class="ttname"><a href="xpt2046_8h.html#abce5dd412f3f040208dab108718fb875">XPT2046_EVENTS</a></div><div class="ttdeci">#define XPT2046_EVENTS</div><div class="ttdef"><b>Definition:</b> <a href="xpt2046_8h_source.html#l00031">xpt2046.h:31</a></div></div>
<div class="ttc" id="struct__xpt2046_html_ae47d989b6ec543113fc386181ea6d98a"><div class="ttname"><a href="struct__xpt2046.html#ae47d989b6ec543113fc386181ea6d98a">_xpt2046::ind</a></div><div class="ttdeci">int ind</div><div class="ttdef"><b>Definition:</b> <a href="xpt2046_8h_source.html#l00067">xpt2046.h:67</a></div></div>
<div class="ttc" id="xpt2046_8h_html_a16726a7a1ffb7ff25c3a2601b578cc19"><div class="ttname"><a href="xpt2046_8h.html#a16726a7a1ffb7ff25c3a2601b578cc19">XPT2046_xy_filtered_test</a></div><div class="ttdeci">MEMSPACE int XPT2046_xy_filtered_test(uint16_t *X, uint16_t *Y)</div></div>
<div class="ttc" id="xpt2046_8h_html_a1f7063812ae4edbb96165244ee717815"><div class="ttname"><a href="xpt2046_8h.html#a1f7063812ae4edbb96165244ee717815">XPT2046_READ_Z1</a></div><div class="ttdeci">#define XPT2046_READ_Z1</div><div class="ttdef"><b>Definition:</b> <a href="xpt2046_8h_source.html#l00035">xpt2046.h:35</a></div></div>
<div class="ttc" id="hal_8c_html_acd8b481ba21b545f53061c5ab7ff451e"><div class="ttname"><a href="hal_8c.html#acd8b481ba21b545f53061c5ab7ff451e">spi_begin</a></div><div class="ttdeci">void spi_begin(uint32_t clock, int pin)</div><div class="ttdoc">SPI chip enable function Function waits for current tranaction to finish before proceeding. </div><div class="ttdef"><b>Definition:</b> <a href="hal_8c_source.html#l00355">hal.c:355</a></div></div>
<div class="ttc" id="user__config_8h_html"><div class="ttname"><a href="user__config_8h.html">user_config.h</a></div><div class="ttdoc">Master include file for project Includes all project includes and defines here. </div></div>
<div class="ttc" id="cordic_8c_html_a46b4b48ef8c0c01099eb3bcdde8aa8db"><div class="ttname"><a href="cordic_8c.html#a46b4b48ef8c0c01099eb3bcdde8aa8db">X</a></div><div class="ttdeci">Cordic_T X</div><div class="ttdoc">Main Cordic routine - used for basic trig and vector rotations We use fixed point numbers...</div><div class="ttdef"><b>Definition:</b> <a href="cordic_8c_source.html#l00102">cordic.c:102</a></div></div>
<div class="ttc" id="structwindow_html_afbd48ebcb41e68d0f458dac593578aa8"><div class="ttname"><a href="structwindow.html#afbd48ebcb41e68d0f458dac593578aa8">window::rotation</a></div><div class="ttdeci">uint8_t rotation</div><div class="ttdef"><b>Definition:</b> <a href="ili9341_8h_source.html#l00046">ili9341.h:46</a></div></div>
<div class="ttc" id="xpt2046_8h_html_a6e35379ae648fa9db798144a9902f8ec"><div class="ttname"><a href="xpt2046_8h.html#a6e35379ae648fa9db798144a9902f8ec">XPT2046_DEBOUNCE</a></div><div class="ttdeci">#define XPT2046_DEBOUNCE</div><div class="ttdef"><b>Definition:</b> <a href="xpt2046_8h_source.html#l00030">xpt2046.h:30</a></div></div>
<div class="ttc" id="struct__xpt2046_html_a271e59b1fe899e8d1199f617bd381b15"><div class="ttname"><a href="struct__xpt2046.html#a271e59b1fe899e8d1199f617bd381b15">_xpt2046::state</a></div><div class="ttdeci">int state</div><div class="ttdef"><b>Definition:</b> <a href="xpt2046_8h_source.html#l00054">xpt2046.h:54</a></div></div>
<div class="ttc" id="xpt2046_8h_html_a3c3571dfe466884bea2a25234aca83ad"><div class="ttname"><a href="xpt2046_8h.html#a3c3571dfe466884bea2a25234aca83ad">sdev</a></div><div class="ttdeci">MEMSPACE int sdev(uint16_t *samples, int size, sdev_t *Z)</div></div>
<div class="ttc" id="send_8c_html_a435d1572bf3f880d55459d9805097f62"><div class="ttname"><a href="send_8c.html#a435d1572bf3f880d55459d9805097f62">uint32_t</a></div><div class="ttdeci">unsigned int uint32_t</div><div class="ttdef"><b>Definition:</b> <a href="send_8c_source.html#l00019">send.c:19</a></div></div>
<div class="ttc" id="cordic_8c_html_ab746e677f466f17031e92ed577fc3c15"><div class="ttname"><a href="cordic_8c.html#ab746e677f466f17031e92ed577fc3c15">Y</a></div><div class="ttdeci">Cordic_T Y</div><div class="ttdef"><b>Definition:</b> <a href="cordic_8c_source.html#l00102">cordic.c:102</a></div></div>
<div class="ttc" id="struct__xpt2046_html"><div class="ttname"><a href="struct__xpt2046.html">_xpt2046</a></div><div class="ttdef"><b>Definition:</b> <a href="xpt2046_8h_source.html#l00051">xpt2046.h:51</a></div></div>
<div class="ttc" id="xpt2046_8h_html_a1dccf53d8f7692a9ae5f272c7a16f462"><div class="ttname"><a href="xpt2046_8h.html#a1dccf53d8f7692a9ae5f272c7a16f462">XPT2046_read</a></div><div class="ttdeci">uint16_t XPT2046_read(uint8_t cmd)</div></div>
<div class="ttc" id="xpt2046_8h_html_acb7288fd027f95ea7db88c6f8c7c2c2a"><div class="ttname"><a href="xpt2046_8h.html#acb7288fd027f95ea7db88c6f8c7c2c2a">XPT2046_spi_init</a></div><div class="ttdeci">MEMSPACE void XPT2046_spi_init(void)</div></div>
<div class="ttc" id="struct__xpt2046_html_a0a1b0401066322d653135eb8db55d198"><div class="ttname"><a href="struct__xpt2046.html#a0a1b0401066322d653135eb8db55d198">_xpt2046::YQ</a></div><div class="ttdeci">uint16_t YQ[XPT2046_EVENTS+1]</div><div class="ttdef"><b>Definition:</b> <a href="xpt2046_8h_source.html#l00071">xpt2046.h:71</a></div></div>
<div class="ttc" id="xpt2046_8h_html_aacb7a75fd6c78e1cd4e87fa930654ef6"><div class="ttname"><a href="xpt2046_8h.html#aacb7a75fd6c78e1cd4e87fa930654ef6">XPT2046_READ_X</a></div><div class="ttdeci">#define XPT2046_READ_X</div><div class="ttdef"><b>Definition:</b> <a href="xpt2046_8h_source.html#l00037">xpt2046.h:37</a></div></div>
<div class="ttc" id="hal_8c_html_a38fdaad472c50237f3d8821a01cda360"><div class="ttname"><a href="hal_8c.html#a38fdaad472c50237f3d8821a01cda360">spi_end</a></div><div class="ttdeci">void spi_end(uint8_t pin)</div><div class="ttdoc">SPI chip disable function wait for current tranaction to finish! </div><div class="ttdef"><b>Definition:</b> <a href="hal_8c_source.html#l00388">hal.c:388</a></div></div>
<div class="ttc" id="hal_8c_html_a9eaae771107e6e01ef45ebe31ca99fdb"><div class="ttname"><a href="hal_8c.html#a9eaae771107e6e01ef45ebe31ca99fdb">chip_select_init</a></div><div class="ttdeci">void chip_select_init(uint8_t pin)</div><div class="ttdoc">CHIP select HAL. </div><div class="ttdef"><b>Definition:</b> <a href="hal_8c_source.html#l00198">hal.c:198</a></div></div>
<div class="ttc" id="ili9341_8c_html_aa55d6901951c7fe057e8d32477b5e122"><div class="ttname"><a href="ili9341_8c.html#aa55d6901951c7fe057e8d32477b5e122">tft</a></div><div class="ttdeci">window * tft</div><div class="ttdef"><b>Definition:</b> <a href="ili9341_8c_source.html#l00045">ili9341.c:45</a></div></div>
<div class="ttc" id="xpt2046_8h_html_a02c4dcf896824df15a98acfbe045d19d"><div class="ttname"><a href="xpt2046_8h.html#a02c4dcf896824df15a98acfbe045d19d">XPT2046_xy_raw</a></div><div class="ttdeci">int XPT2046_xy_raw(uint16_t *X, uint16_t *Y)</div></div>
<div class="ttc" id="posix__tests_8c_html_a8d4059ff64356316a5f13d16cdd90fb5"><div class="ttname"><a href="posix__tests_8c.html#a8d4059ff64356316a5f13d16cdd90fb5">sum</a></div><div class="ttdeci">MEMSPACE uint16_t sum(char *name)</div><div class="ttdoc">sum of a file with 16bit hex and integer results </div><div class="ttdef"><b>Definition:</b> <a href="posix__tests_8c_source.html#l00626">posix_tests.c:626</a></div></div>
<div class="ttc" id="xpt2046_8h_html_aee315feb898d4f6f35389cb3068ad1eb"><div class="ttname"><a href="xpt2046_8h.html#aee315feb898d4f6f35389cb3068ad1eb">XPT2046_READ_Z2</a></div><div class="ttdeci">#define XPT2046_READ_Z2</div><div class="ttdef"><b>Definition:</b> <a href="xpt2046_8h_source.html#l00036">xpt2046.h:36</a></div></div>
<div class="ttc" id="struct__xpt2046_html_a8b4e70a2d7a60543902ac8648c986a31"><div class="ttname"><a href="struct__xpt2046.html#a8b4e70a2d7a60543902ac8648c986a31">_xpt2046::head</a></div><div class="ttdeci">int head</div><div class="ttdef"><b>Definition:</b> <a href="xpt2046_8h_source.html#l00068">xpt2046.h:68</a></div></div>
<div class="ttc" id="cordic_8c_html_a3da94d1c83a43c30add6c05fbbe1f194"><div class="ttname"><a href="cordic_8c.html#a3da94d1c83a43c30add6c05fbbe1f194">Z</a></div><div class="ttdeci">Cordic_T Z</div><div class="ttdef"><b>Definition:</b> <a href="cordic_8c_source.html#l00102">cordic.c:102</a></div></div>
<div class="ttc" id="struct__xpt2046_html_a9730fbc57085ba0f27bf5563fbbce98b"><div class="ttname"><a href="struct__xpt2046.html#a9730fbc57085ba0f27bf5563fbbce98b">_xpt2046::rotation</a></div><div class="ttdeci">int rotation</div><div class="ttdef"><b>Definition:</b> <a href="xpt2046_8h_source.html#l00058">xpt2046.h:58</a></div></div>
<div class="ttc" id="hal_8c_html_a79519dd3475dcb68112f162379287e20"><div class="ttname"><a href="hal_8c.html#a79519dd3475dcb68112f162379287e20">spi_TXRX_buffer</a></div><div class="ttdeci">void spi_TXRX_buffer(const uint8_t *data, int count)</div><div class="ttdoc">SPI write/read buffer. </div><div class="ttdef"><b>Definition:</b> <a href="hal_8c_source.html#l00442">hal.c:442</a></div></div>
<div class="ttc" id="xpt2046_8h_html_ac22e4f7d0ddbfd16b0c685f90db56656"><div class="ttname"><a href="xpt2046_8h.html#ac22e4f7d0ddbfd16b0c685f90db56656">XPT2046_xy_filtered</a></div><div class="ttdeci">MEMSPACE int XPT2046_xy_filtered(uint16_t *X, uint16_t *Y)</div></div>
<div class="ttc" id="xpt2046_8h_html_a69fc6431a2058d4fd8c26af6547cfae5"><div class="ttname"><a href="xpt2046_8h.html#a69fc6431a2058d4fd8c26af6547cfae5">XPT2046_key</a></div><div class="ttdeci">MEMSPACE int XPT2046_key(uint16_t *X, uint16_t *Y)</div></div>
<div class="ttc" id="xpt2046_8h_html_ab0f1cf1130e264b4181a0b525c9be839"><div class="ttname"><a href="xpt2046_8h.html#ab0f1cf1130e264b4181a0b525c9be839">XPT2046_task</a></div><div class="ttdeci">MEMSPACE void XPT2046_task(void)</div></div>
<div class="ttc" id="struct__xpt2046_html_ac3f7953dda5a05a52276892bee461a29"><div class="ttname"><a href="struct__xpt2046.html#ac3f7953dda5a05a52276892bee461a29">_xpt2046::XQ</a></div><div class="ttdeci">uint16_t XQ[XPT2046_EVENTS+1]</div><div class="ttdef"><b>Definition:</b> <a href="xpt2046_8h_source.html#l00070">xpt2046.h:70</a></div></div>
<div class="ttc" id="struct__xpt2046_html_a22287733194e6d32116347f39f77523f"><div class="ttname"><a href="struct__xpt2046.html#a22287733194e6d32116347f39f77523f">_xpt2046::tail</a></div><div class="ttdeci">int tail</div><div class="ttdef"><b>Definition:</b> <a href="xpt2046_8h_source.html#l00069">xpt2046.h:69</a></div></div>
<div class="ttc" id="struct__sdev_html_a2bd0cf80fd334fabaac9100a2538bcb5"><div class="ttname"><a href="struct__sdev.html#a2bd0cf80fd334fabaac9100a2538bcb5">_sdev::mean</a></div><div class="ttdeci">float mean</div><div class="ttdef"><b>Definition:</b> <a href="xpt2046_8h_source.html#l00076">xpt2046.h:76</a></div></div>
<div class="ttc" id="xpt2046_8h_html_a73c23d30b0f5adc10232894c18112778"><div class="ttname"><a href="xpt2046_8h.html#a73c23d30b0f5adc10232894c18112778">XPT2046_key_flush</a></div><div class="ttdeci">MEMSPACE void XPT2046_key_flush(void)</div></div>
<div class="ttc" id="cpu_8h_html_ad0fe97585b8891f5e4f2b9a6426330a4"><div class="ttname"><a href="cpu_8h.html#ad0fe97585b8891f5e4f2b9a6426330a4">MEMSPACE</a></div><div class="ttdeci">#define MEMSPACE</div><div class="ttdef"><b>Definition:</b> <a href="cpu_8h_source.html#l00025">cpu.h:25</a></div></div>
<div class="ttc" id="mathio_8h_html_ad6078f8da2d30ecaef99e0c2d250c0c8"><div class="ttname"><a href="mathio_8h.html#ad6078f8da2d30ecaef99e0c2d250c0c8">printf</a></div><div class="ttdeci">MEMSPACE int printf(const char *format,...)</div></div>
<div class="ttc" id="structwindow_html"><div class="ttname"><a href="structwindow.html">window</a></div><div class="ttdef"><b>Definition:</b> <a href="ili9341_8h_source.html#l00034">ili9341.h:34</a></div></div>
<div class="ttc" id="struct__sdev_html_a053a14f9e4bd729ce23aafdb1e69e48a"><div class="ttname"><a href="struct__sdev.html#a053a14f9e4bd729ce23aafdb1e69e48a">_sdev::sdev</a></div><div class="ttdeci">float sdev</div><div class="ttdef"><b>Definition:</b> <a href="xpt2046_8h_source.html#l00076">xpt2046.h:76</a></div></div>
<div class="ttc" id="struct__sdev_html"><div class="ttname"><a href="struct__sdev.html">_sdev</a></div><div class="ttdef"><b>Definition:</b> <a href="xpt2046_8h_source.html#l00074">xpt2046.h:74</a></div></div>
<div class="ttc" id="ili9341_8h_html"><div class="ttname"><a href="ili9341_8h.html">ili9341.h</a></div><div class="ttdoc">ili9341 driver inspired by Adafruit ili9341 code All code in this file has been rewritten by Mike Gor...</div></div>
<div class="ttc" id="xpt2046_8h_html_aad6adcb00000ad4cdef14ece5e21bd81"><div class="ttname"><a href="xpt2046_8h.html#aad6adcb00000ad4cdef14ece5e21bd81">XPT2046_READ_Y</a></div><div class="ttdeci">#define XPT2046_READ_Y</div><div class="ttdoc">only need 4 commands for reading position or touch information </div><div class="ttdef"><b>Definition:</b> <a href="xpt2046_8h_source.html#l00034">xpt2046.h:34</a></div></div>
<div class="ttc" id="xpt2046_8h_html"><div class="ttname"><a href="xpt2046_8h.html">xpt2046.h</a></div></div>
<div class="ttc" id="xpt2046_8h_html_a0f015f6bedcfd4583ed1133ed6d11963"><div class="ttname"><a href="xpt2046_8h.html#a0f015f6bedcfd4583ed1133ed6d11963">XPT2046_SAMPLES</a></div><div class="ttdeci">#define XPT2046_SAMPLES</div><div class="ttdoc">number of time to read and average results </div><div class="ttdef"><b>Definition:</b> <a href="xpt2046_8h_source.html#l00029">xpt2046.h:29</a></div></div>
<div class="ttc" id="send_8c_html_aba7bc1797add20fe3efdf37ced1182c5"><div class="ttname"><a href="send_8c.html#aba7bc1797add20fe3efdf37ced1182c5">uint8_t</a></div><div class="ttdeci">unsigned char uint8_t</div><div class="ttdef"><b>Definition:</b> <a href="send_8c_source.html#l00017">send.c:17</a></div></div>
<div class="ttc" id="struct__sdev_html_af6ec6d9f07c677d6a25c12c128a60d21"><div class="ttname"><a href="struct__sdev.html#af6ec6d9f07c677d6a25c12c128a60d21">_sdev::min</a></div><div class="ttdeci">uint16_t min</div><div class="ttdef"><b>Definition:</b> <a href="xpt2046_8h_source.html#l00075">xpt2046.h:75</a></div></div>
</div><!-- fragment --></div><!-- contents -->
<!-- start footer part -->
<hr class="footer"/><address class="footer"><small>
Generated on Wed Jan 31 2018 21:22:16 for ESP8266 ILI9341 display support code with printf sources, wire-frame viewer and custom fonts by &#160;<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/>
</a> 1.8.11
</small></address>
</body>
</html>
